<?php
namespace App\Api;

use PhalApi\Api;
use App\Domain\Subscribe as Domain_Subscribe;
/**
 * 预约
 */

class Subscribe extends Api {

	public function getRules() {
        return array(
            'getSubscribeNums' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
			),
            
            'getTome' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'p' => array('name' => 'p', 'type' => 'int', 'desc' => '页数'),
			),
            
            'getMeto' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
                'p' => array('name' => 'p', 'type' => 'int', 'desc' => '页数'),
			),
            
            'setSubscribe' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
                'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'desc' => '主播ID'),
                'type' => array('name' => 'type', 'type' => 'int', 'desc' => '类型，1视频2语音'),
                'sign' => array('name' => 'sign', 'type' => 'string', 'desc' => '签名'),

			),
        );
	}
	
	/**
	 * 预约数量 
	 * @desc 用于获取预约信息数量
	 * @return int code 操作码，0表示成功
	 * @return array info 列表
	 * @return string info[0].nums 数量
	 * @return string msg 提示信息
	 */
	public function getSubscribeNums() {
		$rs = array('code' => 0, 'msg' => '', 'info' => array());
		
        $uid=\App\checkNull($this->uid);
        $token=\App\checkNull($this->token);
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        $domain = new Domain_Subscribe();
		$info = $domain->getSubscribeNums($uid);

        $rs['info'][0]['nums']=$info;
		return $rs;
	}

	/**
	 * 预约我的 
	 * @desc 用于获取预约我的信息
	 * @return int code 操作码，0表示成功
	 * @return array info
	 * @return string info[].subscribeid 预约ID
	 * @return string info[].coin 用户余额
	 * @return string info[].status 状态，0未赴约1已预约
	 * @return string msg 提示信息
	 */
	public function getTome() {
		$rs = array('code' => 0, 'msg' => '', 'info' => array());
		
        $uid=\App\checkNull($this->uid);
        $token=\App\checkNull($this->token);
        $p=\App\checkNull($this->p);
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        $domain = new Domain_Subscribe();
		$info = $domain->getTome($uid,$p);

        $rs['info']=$info;
		return $rs;
	}

	/**
	 * 我预约的 
	 * @desc 用于获取获预约我的信息
	 * @return int code 操作码，0表示成功
	 * @return array info
     * @return string info[].subscribeid 预约ID
     * @return string info[].status 状态，0未赴约1已预约
	 * @return string msg 提示信息
	 */
	public function getMeto() {
		$rs = array('code' => 0, 'msg' => '', 'info' => array());
		
        $uid=\App\checkNull($this->uid);
        $token=\App\checkNull($this->token);
        $p=\App\checkNull($this->p);
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        $domain = new Domain_Subscribe();
		$info = $domain->getMeto($uid,$p);

        $rs['info']=$info;
		return $rs;
	}

	/**
	 * 预约
	 * @desc 用于用户预约主播
	 * @return int code 操作码，0表示成功
	 * @return array info 列表
	 * @return string msg 提示信息
	 */
	public function setSubscribe() {
		$rs = array('code' => 0, 'msg' => '', 'info' => array());
		
        $uid=\App\checkNull($this->uid);
        $token=\App\checkNull($this->token);
        $liveuid=\App\checkNull($this->liveuid);
        $type=\App\checkNull($this->type);
        $sign=\App\checkNull($this->sign);
        
        if($uid<1 || $token=='' || $liveuid<1 || $type<1 || $sign=='' ){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }
        
        $checkdata=array(
            'uid'=>$uid,
            'token'=>$token,
            'liveuid'=>$liveuid,
            'type'=>$type,
        );
        
        $issign=\App\checkSign($checkdata,$sign);
        if(!$issign){
            $rs['code']=1001;
			$rs['msg']=\PhalApi\T('签名错误');
			return $rs;	
        }
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        $data=array(
            'uid'=>$uid,
            'liveuid'=>$liveuid,
            'type'=>$type,
        );
        $domain = new Domain_Subscribe();
		$info = $domain->setSubscribe($data);

		return $info;
	}

    
    
    
    
}
